package com.diudiutechnology.www.yadiudiu.yadiudiu.main.MyAdapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.diudiutechnology.www.yadiudiu.R;
import com.diudiutechnology.www.yadiudiu.util.utils.Constant;
import com.diudiutechnology.www.yadiudiu.yadiudiu.model.HomePageModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/8/31.
 */

public class HomePageAdapter extends BaseAdapter {

    private Context mContext;
    List<HomePageModel.GoodsBean> model= new ArrayList<>();
    public HomePageAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return model.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    public void addItem( List<HomePageModel.GoodsBean> model){

        this.model=model;
        notifyDataSetChanged();
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_home_page, null);


            holder.item_original_price = (TextView) convertView
                    .findViewById(R.id.item_original_price);
             holder.itemImage = (ImageView) convertView
                    .findViewById(R.id.item_image);
            holder.item_title = (TextView) convertView
                    .findViewById(R.id.item_title);
            holder.item_present_price = (TextView) convertView
                    .findViewById(R.id.item_present_price);
            holder.item_snap = (TextView) convertView
                    .findViewById(R.id.item_snap);
            holder.item_progressBar = (ProgressBar) convertView
                    .findViewById(R.id.item_progressBar);
            holder.idem_robbed = (TextView) convertView
                    .findViewById(R.id.idem_robbed);


            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        HomePageModel.GoodsBean goodsBean = model.get(position);
        holder.item_original_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG|Paint.ANTI_ALIAS_FLAG);
        Glide.with(mContext).load(Constant.HTTP + goodsBean.getImg()).into(holder.itemImage);
        holder.item_original_price.setText(goodsBean.getOprice());
        holder.item_present_price.setText(goodsBean.getPprice());
        holder.item_title.setText(goodsBean.getSubject());
        holder.idem_robbed.setText("已抢 "+goodsBean.getProportion()+"%");
        holder.item_progressBar.setMax(100);
        holder.item_progressBar.setProgress(goodsBean.getProportion());
        return convertView;
    }

    class ViewHolder {
        TextView item_original_price;
        ImageView itemImage;
        TextView item_title;
        TextView item_present_price;
        TextView item_snap;
        TextView idem_robbed;
        ProgressBar item_progressBar;

    }
}


